<template>
	<view class="flex-col page  ">
		<view class="flex-col section_2">
			<view class="">
				<u-tabs active-color="#D85886" bg-color="#fff" bar-width="116" inactive-color="#F692B6" font-size="28"
					:list="tabs" :is-scroll="false" :current="current" @change="change"></u-tabs>
			</view>
			<view class="px-3" v-if="!current">
				<template v-if="list1.length">
					<div class="coupons mt-12" v-for="(v,i) in list1" :key="i">
						<div class="coupon ">
							<div class="coupon-intro bac-jian  d-flex align-items-center">
								<view class="d-flex text-white  align-items-center flex-column" v-if="v.min_price==0">
									<view class="d-flex align-items-baseline">
										<view class="font-36 text-white font-600">{{v.reduce_price}}</view>
										<view class="ps-1">元</view>
									</view>
									<view class="">立减券</view>
								</view>
								<view class="d-flex text-white  align-items-center flex-column" v-else>
									<view class="d-flex align-items-baseline">
										<view class="font-36 text-white font-600">{{v.reduce_price}}</view>
										<view class="ps-1">元</view>
									</view>
									<view class="">满减券</view>
								<!-- 	<view class="d-flex align-items-baseline justify-content-between w-100">
										<view class="ps-1">满</view>
										<view class="font-36 text-white font-600 ps-2">{{v.min_price}}</view>
									</view>
									<view class="d-flex align-items-baseline justify-content-between w-100">
										<view class="ps-1">减</view>
										<view class="font-36 text-white font-600 ps-2">{{v.reduce_price}}</view>
									</view> -->
								</view>
							</div>
							<div class="coupon-value">
								<view class="d-flex w-100 justify-content-between ">
									<view class="ps-3 p-3 flex-1">
										<view class="font-20 text-222426 pb-3">{{v.coupon_name}}</view>
										<view class="text-AAB5BF font-14 pb-1">有效期：</view>
										<view class="text-222426 font-14">
											<text>{{v.start_time|setTime}}</text>-<text>{{v.end_time|setTime}}</text>
										</view>
									</view>
									<view class="font-14 status px-2 mx-1 ">
										未使用
									</view>
								</view>
							</div>
						</div>
					</div>
				</template>
				<view v-else class="empty d-flex justify-content-center flex-column align-items-center h-100">
					<image src="../../static/imgs/empty.png" class="img" />
					<view class="text-AAB5BF mt-1 pt-3">暂时没有数据</view>
				</view>
			</view>

			<view class="px-3" v-if="current==1">
				<template v-if="list2.length">
					<div class="coupons mt-12" v-for="(v,i) in list2" :key="i">
						<div class="coupon ">
							<div class="coupon-intro  d-flex align-items-center  bg-AAB5BF">
								<view class="d-flex text-white  align-items-center flex-column" v-if="v.min_price==0">
									<view class="d-flex align-items-baseline">
										<view class="font-36 text-white font-600">{{v.reduce_price}}</view>
										<view class="ps-1">元</view>
									</view>
									<view class="">立减券</view>
								</view>
								<view class="d-flex text-white  align-items-center flex-column" v-else>
									<view class="d-flex align-items-baseline">
										<view class="font-36 text-white font-600">{{v.reduce_price}}</view>
										<view class="ps-1">元</view>
									</view>
									<view class="">满减券</view>
								<!-- 	<view class="d-flex align-items-baseline justify-content-between w-100">
										<view class="ps-1">满</view>
										<view class="font-36 text-white font-600 ps-2">{{v.min_price}}</view>
									</view>
									<view class="d-flex align-items-baseline justify-content-between w-100">
										<view class="ps-1">减</view>
										<view class="font-36 text-white font-600 ps-2">{{v.reduce_price}}</view>
									</view> -->
								</view>
							</div>
							<div class="coupon-value">
								<view class="d-flex w-100 justify-content-between ">
									<view class="ps-3 p-3 flex-1">
										<view class="font-20 text-222426 pb-3">{{v.coupon_name}}</view>
										<view class="text-AAB5BF font-14 pb-1">有效期：</view>
										<view class="text-222426 font-14">
											<text>{{v.start_time |setTime}}</text>-<text>{{v.end_time| setTime}}</text>
										</view>
									</view>
									<view class="font-14 status px-2 mx-1 text-AAB5BF">
										已过期
									</view>
								</view>
							</div>
						</div>
					</div>
				</template>
				<view v-else class="empty d-flex justify-content-center flex-column align-items-center h-100">
					<image src="../../static/imgs/empty.png" class="img" />
					<view class="text-AAB5BF mt-1 pt-3">暂时没有数据</view>
				</view>
			</view>

			<view class="px-3" v-if="current==2">
				<template v-if="list3.length">
					<div class="coupons mt-12" v-for="(v,i) in list3" :key="i">
						<div class="coupon ">
							<div class="coupon-intro use  d-flex align-items-center">
								<view class="d-flex text-white  align-items-center flex-column" v-if="v.min_price==0">
									<view class="d-flex align-items-baseline">
										<view class="font-36 text-white font-600">{{v.reduce_price}}</view>
										<view class="ps-1">元</view>
									</view>
									<view class="">立减券</view>
								</view>
								<view class="d-flex text-white  align-items-center flex-column" v-else>
									<view class="d-flex align-items-baseline">
										<view class="font-36 text-white font-600">{{v.reduce_price}}</view>
										<view class="ps-1">元</view>
									</view>
									<view class="">满减券</view>
									<!-- <view class="d-flex align-items-baseline justify-content-between w-100">
										<view class="ps-1">满</view>
										<view class="font-36 text-white font-600 ps-2">{{v.min_price}}</view>
									</view>
									<view class="d-flex align-items-baseline justify-content-between w-100">
										<view class="ps-1">减</view>
										<view class="font-36 text-white font-600 ps-2">{{v.reduce_price}}</view>
									</view> -->
								</view>
							</div>
							<div class="coupon-value">
								<view class="d-flex w-100 justify-content-between ">
									<view class="ps-3 p-3 flex-1">
										<view class="font-20 text-666D73 pb-3">{{v.coupon_name}}</view>
										<view class="text-AAB5BF font-14 pb-1">有效期：</view>
										<view class="text-AAB5BF font-14">
											<text>{{v.start_time |setTime}}</text>-<text>{{v.end_time|setTime}}</text>
										</view>
									</view>
									<view class="font-14 status text-666D73 px-2 mx-1 ">
										已使用
									</view>
								</view>
							</div>
						</div>
					</div>
				</template>
				<view v-else class="empty d-flex justify-content-center flex-column align-items-center h-100">
					<image src="../../static/imgs/empty.png" class="img" />
					<view class="text-AAB5BF mt-1 pt-3">暂时没有数据</view>
				</view>
			</view>
		</view>





	</view>
</template>

<script>
	import moment from 'moment'
	import {
		topUpDetail,
		useDetail
	} from '../../common/commonData.js';
	export default {
		data() {
			return {
				tabs: [{
						id: 1,
						name: '未使用 (0)'
					},
					{
						id: 2,
						name: '已过期 (0)'
					}, {
						id: 2,
						name: '已使用 (0)'
					},
				],
				current: 0,
				list1: [],
				list2: [],
				list3: [],
			};
		},

		onLoad() {
			uni.hideShareMenu()
			if (!this.vuex_has_login) {
				this.$u.toast('请先登录');
				return
			} else {
			}
			this.getCouponList()
		},
		methods: {
			getCouponList() {
				this.$u.api.getUserAllCoupon().then((res) => {
					res.data.forEach((e) => {
						// console.log(moment().format('YYYY-MM-DD'));
						// console.log(e.end_time);
						// console.log(moment().format('YYYY-MM-DD') >= e.end_time);
						if (!e.is_used && moment().format('YYYY-MM-DD') > e.end_time) {
							this.list2.push(e)
						} else if (!e.is_used) {
							this.list1.push(e)
						} else {
							this.list3.push(e)
						}
					})
					this.$nextTick(() => {
						this.tabs[0].name = `未使用（${this.list1.length}）`
						this.tabs[1].name = `已过期（${this.list2.length}）`
						this.tabs[2].name = `已使用（${this.list3.length}）`
					})
				})

			},
			//tabs
			change(index) {
				this.current = index;
			},
			//复制
			copy(item) {
				//提示模板
				uni.setClipboardData({
					data: item.order_num, //要被复制的内容
					success: () => {
						//复制成功的回调函数
						uni.showToast({
							//提示
							title: '复制成功'
						});
					}
				});
			},
		},
	};
</script>

<style scoped lang="scss">
	.page {
		$background-color: #eee;
		$radius-size: 8px;

		.coupons {
			width: 100%;

			.coupon {
				margin-bottom: 20px;
				display: flex;

				>div {
					padding: 10px 20px;
					border-radius: $radius-size;
				}

				.bac-jian {
					background: linear-gradient(326.28deg, #D85886 1.25%, #F692B6 100%);
				}

				.coupon-intro {
					position: relative;
					padding: 0;
					width: 194rpx;
					justify-content: center;
					ul {
						color: #aaa;
						padding-left: 20px;
					}

					&:after {
						content: ' ';
						border: 2px dashed white;
						height: 100%;
						position: absolute;
						top: 0;
						right: -2px;
						z-index: 2;
					}
				}

				.coupon-value {
					padding: 0;
					display: flex;
					flex: 1;
					position: relative;
					background: #F2F9FC;
					color: #fff;
					font-size: 38px;
					align-items: center;

					&:before {
						content: ' ';
						width: $radius-size * 2;
						height: $radius-size * 2;
						position: absolute;
						top: -$radius-size;
						left: -$radius-size;
						border-radius: 100%;
						background: white;
					}

					&:after {
						content: ' ';
						width: $radius-size * 2;
						height: $radius-size * 2;
						position: absolute;
						bottom: -$radius-size;
						left: -$radius-size;
						border-radius: 100%;
						background: white;
					}

					.status {
						writing-mode: vertical-lr;
						text-align: center;
						color: #FA9C10;
						border-left: 2px dashed #DAE4EE;

					}
				}
			}
		}

	}

	.empty {
		padding-top: calc(30vh - 244rpx);

		image {
			width: 288rpx;
			height: 304rpx;
		}
	}
	.use{
		background: linear-gradient(326.28deg, #D85886 1.25%, #F692B6 100%);
	}
</style>